import java.util.ArrayList;
import java.util.List;

public class SolutionInterview16_20 {
    public List<String> getValidT9Words(String num, String[] words) {
        List<String> list=new ArrayList<>();
        int[] f=new int[]{2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
        for (String word : words) {
            StringBuilder stringBuilder=new StringBuilder();
            for (char c : word.toCharArray()) {
                stringBuilder.append(f[c-'a']);
            }
            if (num.equals(stringBuilder.toString())){
                list.add(word);
            }
        }
        return list;
    }

    public static void main(String[] args) {
        System.out.println(new SolutionInterview16_20().getValidT9Words("8733",new String[]{"tree", "used"}));
    }
}
